<?
// +----------------------------------------------------------------------
// | 联盟成员列表
// +----------------------------------------------------------------------
// | Author: TongBC <50249101@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/03/24
// +----------------------------------------------------------------------
//exit;
ob_start(); 
include("common/header.html");
include("common/left.html");
include("common/page.php");
include("class/SimpleExcel.class.php");
$out_html=ob_get_contents();
ob_end_clean();
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

if(!$_SESSION['memberID']){exit("<script>window.location='dlogin.html'</script>");}

$sql = "select fid from  pft_distributor_union_SE where fid={$_SESSION['sid']} limit 1";
$GLOBALS['le']->query($sql);
if(!$row=$GLOBALS['le']->fetch_assoc()){
    exit('您不是盟主 无权访问该页面');
}

$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
if($_REQUEST['act']=='loadExcel'){
    $currentPage = 1;
    $pageSize = 9999;
}
$txt=$_REQUEST['txt'];
$dtype=$_REQUEST['dtype'];
$ctype=$_REQUEST['com_type'];
$prov=$_REQUEST['d_province']?$_REQUEST['d_province']:0;
$city=$_REQUEST['d_city']?$_REQUEST['d_city']:0;
$tpl=$b=$a=$a_sort=array();
if($txt && $txt!="请输入企业名称\分销账号\手机"){
	$tj=" and (instr(dname,'".$txt."') or instr(cname,'".$txt."') or account='".$txt."' or mobile='".$txt."')";
}
if($prov || $city || $ctype){
	$a_t=" left join pft_member_extinfo e on e.fid=m.id ";
	$a_tj.=$prov?" and province=".$prov:"";
	$a_tj.=$city?" and city=".$city:"";
	if($ctype){
		$a_tj.=" and (";
		foreach($ctype as $v){
			$a_tj.="instr(com_type,'".$v."') or ";
		}
		$a_tj=trim($a_tj,"or ").")";
	}
}

	$ltitle="供应商列表";
	$sel1="select dname,cname,account,mobile,m.id ";
	$sel2="select count(*) total ";
	$sel="from pft_union_member_info_SE r left join pft_member m on m.id=r.memberID ".$a_t." where m.status in (0,3) ".$tj.$a_tj." and r.dstatus=0 and r.fid=".$_SESSION['sid'];

$GLOBALS['le']->query($sel1.$sel." limit ".($currentPage-1)*$pageSize.",".$pageSize);
while($row=$GLOBALS['le']->fetch_assoc()){
/*
	switch($row['son_id_type']){
		case 0:$row['s_type']="分销商";break;
		case 1:$row['s_type']="资源方";break;
	}
	if($dtype==1){$row['s_type']="供应商";}
	switch($row['ship_type']){
		case 0:$row['type']="供销关系";break;
		case 1:$row['type']="从属关系";break;
		case 2:$row['type']="平级关系";break;
		case 3:$row['type']="推荐关系";break;
	}
*/
	$a_sort[$row['id']]=$row;
} 
$GLOBALS['le']->query($sel2.$sel);
$GLOBALS['le']->fetch_assoc();
$total=$GLOBALS['le']->f("total");
// $total = sizeof($a_sort);
$parid=array_keys($a_sort);
if($dtype==0){
	if($parid){
		$_a=simplexml_load_string($s->PFT_Member_Fund(implode(",",$parid),1,$_SESSION['sid']));
		foreach($_a as $v){
			$a[(int)$v->UUfid]=$v->UUkmoney/100;
		}
		$_b=simplexml_load_string($s->PFT_Member_Fund(implode(",",$parid),2,$_SESSION['sid']));
		foreach($_b as $v){
			$b[(int)$v->UUfid]=$v->UUbasecredit/100;
		}
	}
}
$txt=$txt?$txt:"请输入企业名称\分销账号\手机";
if($_REQUEST['act']=='loadExcel'){
    $filename=date('YmdHis').'集团成员列表';
	$Excel[0]['a']='企业名称（账号）';
	$Excel[0]['b']='联系人';
	$Excel[0]['c']='手机号码';
	$Excel[0]['d']='资金金额';
	$i=1;
	foreach($a_sort as $data){
		$n++;
		$Excel[$n]['a']=$data['dname'].'('.$data['account'].')';
		$Excel[$n]['b']=$data['cname'];
		$Excel[$n]['c']=$data['mobile'];
		$Excel[$n]['d']=(float)$a[$data['id']];
	}
	$xls = new SimpleExcel('UTF-8', true,'ml');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
	exit;
}
echo $out_html;
?>
<title><?=$ltitle?></title>
<link rel="stylesheet" type="text/css" href="css/distri.css"/>
<link rel="stylesheet" type="text/css" href="css/jump.css"/>
<script type="text/javascript" src="js/jquery.getareas.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
    $("#area").getAreas({update:true,pro_id:<?=$prov?>,city_id:<?=$city?>,county_id:0,depth:2});
});
function setFund(id,a){
    $('#fund').show();
    $('#mask').show();
    var td=$(a).parent().parent().children();
    $("#info").html(td.eq(0).html());
    $("#tmoney").html(td.eq(3).html());
    $("#cmoney").val(td.eq(4).html());
    $("#did").val(id);
    $("#ali").val('通过支付宝');
}
function cl(c){
    if(c.value=="请输入企业名称\\分销账号\\手机"){
        c.value="";
        c.style.color="#000";
        return;
    }
    if(c.value==""){
        c.value="请输入企业名称\\分销账号\\手机";
        c.style.color="#888";
        return;
    }
}
function close(){
    $('#fund').hide();
    $('#mask').hide();
}
function chTpl(d,t){
    if(d)alert($.ajax({url:"call/setLowTpl.php",data:{did:d,tplid:t},async:false}).responseText);
}
function paytype(t){
    if(!$('#money').val()){
        alert('请填写金额');
        return false;
    }
    var b=$('#ali');
    var f=document.forms['pay'];
    if(t==1){
        if(b.val()=="完成/重新支付"){
            window.location.reload();
            return false;
        }
        else{
            b.val("完成/重新支付");
        }
        f.target='_blank';
        f.action='recharge.php';
    }
    else if(t==0){
        f.target='ifr';
        f.action='call/setFund.php';
    }
    f.submit();
}
function break_off(id,dtype){
    if(confirm('若想重新进入联盟，只能由分销商自己申请。确定删除？')){
        // $.getJSON("call/jh_alliance.php", {action:"out",dtype:dtype, mid:id}, function(json){
            // if(json['status']!='ok'){alert(json['msg']);}
            // else{alert('删除成功!');window.location.reload();}
        // });
		$.getJSON("call/chRela.php", { dtype:dtype, id:id}, function(json){
            //alert(json['id']+'|'+json['dtype']+'|'+json['parent_id']+'|'+json['sessionmemberID']+'|'+json['son_id']);
            if(json['status']!='ok'){alert(json['msg']);}
            else{alert('删除成功!');window.location.reload();}
        });
    }
		

}
function transfer(id,a){
    $('#fund').show();
    $('#mask').show();
    var td=$(a).parent().parent().children();
    $("#info").html(td.eq(0).html());
    $("#tmoney").html(td.eq(3).html());
    $("#did").val(id);
    $("#act").val("z");
}
</script>
<style type="text/css">
.fund{display:none; background:url(images/pkpopup_bg.png) no-repeat; left:50%; margin-left:-195px; margin-top:-100px; position:absolute; top:50%; width:390px; height:200px; padding:5px 20px 15px; z-index:100;}
.fund table{ margin-top:0px;}
.fund table thead th{text-align:left; padding:0 7px; height:40px; line-height:40px; border-bottom:2px solid #999; font-weight: bold; font-size:14px;}
.fund table thead{ background-color:transparent; height:auto; border:0;}
.fund table thead th span{ cursor:pointer; display:inline-block; float:right; width:17px; height:17px; background:url(images/close.png) no-repeat; margin-top:12px;}
.fund table td{ height:auto; padding:15px; text-align:left;}
.fund table td p{font-weight:bold; text-align:left;height:30px; line-height:30px;}
.fund table td p font{margin:0 5px;}
.fund table td span{line-height:30px;}
.fund table td span.yuck{ margin-left:55px;}
#money{ height:18px; line-height:18px; padding:2px 4px; border:1px solid #CCCCCC; width:60px; margin:12px 4px 0;}
.fund table td span.qd input{ background:url(images/btn23bg2.png) repeat-x; border:1px solid #FF8000; border-bottom-color:#F55C00; height:25px;  line-height:23px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#FFF; font-weight:bold; margin:15px 0 0 55px; *margin-left:10px; padding:0 10px;}
.fund table td span.qd input:hover{ background:url(images/btn23bg22.png) repeat-x;}
.mc_title a{float:right; margin-right:50px; line-height:25px;}
.dismtab tbody td.txtlf{ text-align:left; padding-left:8px;}
#excel{width:80px;height:30px;float:right;border:none;background:#00AAD3;cursor:pointer;color:#FFF;}
#excel:hover{background:#03A2C9;}
</style>
<iframe name="ifr" style="display:none;"></iframe>
<div class="r_content">
    <h3 class="mc_title">
    <span class="mctit_1"><span class="mctit_2"><?=$ltitle?></span></span>
    </h3>
    <div class="dissear_box">
        <form id="search">
            <input type="hidden" name="dtype" value="<?=$_REQUEST['dtype']?>"/>
            <input type="hidden" name="act" id="act" />
            <span><input type="button" id="excel" class="btn" value="导出"/></span>
            <span class="fltrig"><input type="submit" class="searbtn" value=""/></span>
            <p>
                <b>搜索条件：</b><span><input type="text" class="sertxt" name="txt" onfocus="cl(this)" onblur="cl(this)" value="<?=$txt?>" /></span>
                <b>区域搜索：</b>
                <span id="area">
                </span>
            </p>

        </form>
    </div>
    <div id="fund" class="fund">
        <table class="dismtab">
            <thead>
                <th><span onclick="$('#fund').hide();$('#mask').hide();"></span><?if($dtype==7){echo "线下充值";}else{echo "分销还款/充值";}?> - <font id="info" color="green"></font></th>
            </thead>
            <tbody>
                <tr>
                    <td>
                      <form name="pay" action="call/setFund.php" target="ifr">
                        <input type="hidden" name="did" id="did" />
                    <?    if($dtype==7){?>
                        <input type="hidden" name="act" id="act" value="z" />
                        <span class="yuck">线下充值其资金账户<input type="text" name="tmoney" id="money" />元</span><br />
                        <span class="qd"><input type="button" onclick="paytype(2)" value="确 认 充 值" /></span>
                        <span class="qd"><input type="button" onclick="$('#fund').hide();$('#mask').hide();" value=" 取 消 " /></span>
                    <?    }else{?>
                        <input type="hidden" name="act" id="act" value="r" />
                        <p>当前供应账户余额<font id="tmoney" color="green"></font>元</p>
                        <span class="yuck">预存/还款<input type="text" name="money" id="money" />元</span><br />
                        <span class="qd"><input type="button" onclick="paytype(0)" value="使用账户余额" /></span>
                        <span class="qd"><input type="button" id="ali" onclick="paytype(1)" value="通过支付宝" /></span>
                    <?    }?>
                        <!-- <br />
                        <span>&nbsp;&nbsp;允许预支最多<input type="text" name="cmoney" id="cmoney" />元</span>
                        <span class="qd"><input type="submit" onclick="$('#act').val('c')" value=" 修 改 " /></span> -->
                      </form>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <table class="dismtab">
        <thead>
            <th>企业名称（账号）</th>
            <th>联系人</th>
            <th>手机号码</th>
        <?    if($dtype==7){?>
            <th>资金余额</th>
        <?    }else{?>
            <th title="供应商余额=账户余额+授信额度">授信余额</th>
<!--                    <th>授信额度</th>-->
            <?    if($dtype==0){?>

            <?    }?>
        <?    }?>
            <th>操作</th>
        </thead>
        <tbody>
        <?foreach($a_sort as $v){?>
            <tr>
                <td style="text-align:left;padding-left:10px;"><a target="_blank" href="userinfo.html?id=<?=$v['id']?>"><?=$v['dname']?>（ID:<?=$v['account']?>）</a></td>
                <td class="txtlf"><?=$v['cname']?></td>
                <td><?=$v['mobile']?></td>
                <?if($dtype==7){?>
                <td><?=(float)$a[$v['id']]?></td>
                <td class="">
                <?    if($v['son_id_type']==0){?>
                    --<!-- <a href="javascript:void(0)" onclick="setFund(<?=$v['id']?>,this)">充值</a> -->
                <?    }
                    else{?>
                    --
                <?   }
                }else{?>
                <td title="供应商余额=账户余额(<?=$a[$v['id']]?>)+授信额度(<?=$b[$v['id']]?>)"><?=(float)($a[$v['id']]+$b[$v['id']])?></td>
<!--                        <td>--><?//=(float)?><!--</td>-->
                <?if($dtype==0){?>

                <td class="tdrig">
                    <a href="repayment.html?id=<?=$v['id']?>">授信/预存</a>
                <?    }else{?>
                <td class="tdrig">
                    <a href="javascript:void(0)" onclick="setFund(<?=$v['id']?>,this)">预存/还款</a>
                <?    }?>
                    <a href="javascript:void(0);" onclick="break_off(<?=$v['id']?>,<?=$dtype?>)">删除</a>
            <?    }?>
               
                </td>
            </tr>
        <?    }
            if($dtype==7){?>
            <tr>
                <td style="text-align:right;color:red;" colspan="3">合计：</td>
                <td><?=(float)$count?></td>
                <td><a href="rrecord.html">记录</a></td>
            </tr>
        <?    }?>
        </tbody>
    </table>
    <?page($total,$currentPage,$pageSize);?>
</div>
<script>
$(function(){
    $("#excel").click(function(){
        $("#act").val("loadExcel");
        $("#search").submit();
    });
});
</script>
<?include("common/footer.html")?>